#pragma once
#include <vulkan/vulkan_core.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "ce_vulkan_struct.h"

class CE_VulkanPipeline;
class CE_VulkanShader;
class CE_VulkanContext;
class CE_VulkanPass;

class CE_VulkanObject
{
private:
    CE_VulkanContext *_context;
    int _flag;
    CE_VulkanObjectTypeE _type;

    VkBuffer _vertexBuffer; // 顶点数据Buffer
    VkBuffer _indexBuffer;  // 顶点index数据buffer
    VkDeviceSize _vertexSize;
    VkDeviceSize _indexSize;

    VkDeviceMemory _vertexMemory;
    VkDeviceMemory _indexMemory;

    CE_VulkanPipeline *_pipeline;

    std::vector<VkFramebuffer> _swapChainFramebuffers; // 添加一个集合存储帧缓冲对象
    void _createFramebuffers();

    std::vector<VkCommandBuffer> _commandBuffers;
    bool _isClear = false;
    float _color[COLOR_SIZE];

    void _cleanupBuffers();
    void _cleanupFramebuffers();

public:
    CE_VulkanObject(CE_VulkanContext *context, CE_VulkanObjectTypeE type);
    void setVertexs(std::vector<Vertex> vertices, std::vector<uint32_t> indices);
    void setRendererPipeline(CE_VulkanPipeline *pipeline);
    void setClear(bool clear);
    void setColor(float r, float g, float b, float a);
    void updateRender();
    VkCommandBuffer getCommandBuffer(uint32_t index);

    ~CE_VulkanObject();
};
